<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>全栈开发(AngularJS) | 静待花开</title><meta name="author" content="brad 随风起舞"><meta name="copyright" content="brad 随风起舞"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="在这篇博客中,将展示Spring Boot，Spring Security和AngularJS如何协同工作以提供愉悦和安全的用户体验。通过使用AngularJS来安全的消费RESTful服务。首先，您将通过在AngularJS中发送每个请求的授权标头开始。然后，您将创建一个登录页面并更新Spring Security配置以支持登录和注销身份验证过程。 在Angular Js中发送的每个访问都带着授">
<meta property="og:type" content="article">
<meta property="og:title" content="全栈开发(AngularJS)">
<meta property="og:url" content="https://zhangbo4881820.gitee.io/myblog/posts/12008/index.html">
<meta property="og:site_name" content="静待花开">
<meta property="og:description" content="在这篇博客中,将展示Spring Boot，Spring Security和AngularJS如何协同工作以提供愉悦和安全的用户体验。通过使用AngularJS来安全的消费RESTful服务。首先，您将通过在AngularJS中发送每个请求的授权标头开始。然后，您将创建一个登录页面并更新Spring Security配置以支持登录和注销身份验证过程。 在Angular Js中发送的每个访问都带着授">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2019-11-05T02:58:05.000Z">
<meta property="article:modified_time" content="2023-09-07T09:44:01.886Z">
<meta property="article:author" content="brad 随风起舞">
<meta property="article:tag" content="实战">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/myblog/img/favicon.png"><link rel="canonical" href="https://zhangbo4881820.gitee.io/myblog/posts/12008/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/myblog/css/index.css"><link rel="stylesheet" href="/myblog/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="/myblog/css/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/myblog/',
  algolia: undefined,
  localSearch: {"path":"/myblog/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '全栈开发(AngularJS)',
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2023-09-07 17:44:01'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 7.0.0-rc2"><link rel="alternate" href="/myblog/atom.xml" title="静待花开" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/myblog/" title="静待花开"><span class="site-name">静待花开</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/myblog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 分享</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/myblog/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/myblog/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/myblog/movies/"><i class="fa-fw fas fa-video"></i><span> 视频</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/myblog/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/myblog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">全栈开发(AngularJS)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-11-05T02:58:05.000Z" title="发表于 2019-11-05 10:58:05">2019-11-05</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-09-07T09:44:01.886Z" title="更新于 2023-09-07 17:44:01">2023-09-07</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/myblog/categories/%E5%AE%9E%E6%88%98/">实战</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="全栈开发(AngularJS)"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><p>在这篇博客中,将展示Spring Boot，Spring Security和AngularJS如何协同工作以提供愉悦和安全的用户体验。<br>通过使用AngularJS来安全的消费RESTful服务。首先，您将通过在AngularJS中发送每个请求的授权标头开始。<br>然后，您将创建一个登录页面并更新Spring Security配置以支持登录和注销身份验证过程。</p>
<h1 id="在Angular-Js中发送的每个访问都带着授权头"><a href="#在Angular-Js中发送的每个访问都带着授权头" class="headerlink" title="在Angular Js中发送的每个访问都带着授权头"></a>在Angular Js中发送的每个访问都带着授权头</h1><p>Basic Authentication 允许客户端发送Base-64编码的凭据,通过在每个http访问中使用授权的header.<br>这意味着每个访问都是独立的,并且服务器不会对客户端维护任何状态信息.</p>
<p>当你发送一个带授权头的请求时,让一个 HTTP 拦截器来处理比在$http方法中人工指定授权头要好很多.</p>
<h2 id="在Angular-Js-中添加拦截器"><a href="#在Angular-Js-中添加拦截器" class="headerlink" title="在Angular Js 中添加拦截器"></a>在Angular Js 中添加拦截器</h2><p>当一个请求和响应在基于HTTP中交互时,此时你想要注入一些自定义的逻辑,然后就是HTTP拦截器出手时机.<br>一个http拦截器总是为了如认证,授权,管理session状态,记录日志,修改响应,重写url,处理错误,缓存,添加自定义头,在请求响应中添加时间戳,在http的请求,响应前后加密解密请求响应信息.</p>
<p><img src="/myblog/../../../../image/http-request-response.png"></p>
<p>Angular Js 支持4种http拦截器:request ,response,requestError,responseError</p>
<ul>
<li><p>request拦截器是在$http发送请求到服务端时候被调用.request方法有一个config对象作为输入参数,在添加,修改,或者从这个<br>对象中删除数据中之后返回一个config对象</p>
</li>
<li><p>response拦截器是在$http从服务端接受到响应的时候调用.response方法有一个response参数,在返回一个response对象之前<br>可以修改response数据或添加一系列新值,调用其他模块服务,或服务端调用.</p>
</li>
<li><p>requestError拦截器是在请求过程中有任何错误抛出就会调用这个拦截器</p>
</li>
<li><p>responseError拦截器是在服务端任何调用失败,就会调用这个拦截器.并且应用需要根据不同的状态码去触发一些动作</p>
</li>
</ul>
<h3 id="authInterceptor-js"><a href="#authInterceptor-js" class="headerlink" title="authInterceptor.js"></a><strong>authInterceptor.js</strong></h3><p>在authInterceptor.js文件中创建一个名字为AuthInterceptor的拦截器</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">app.factory(&#x27;AuthInterceptor&#x27;,[function () &#123;</span><br><span class="line">    return &#123;</span><br><span class="line">        &#x27;request&#x27; : function (config) &#123;</span><br><span class="line">            config.headers = config.headers || &#123;&#125;;</span><br><span class="line">            var encodedString = btoa(&quot;admin:password&quot;);</span><br><span class="line">            config.headers.Authorization = &#x27;Basic &#x27; + encodedString;</span><br><span class="line">            return config;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;])</span><br></pre></td></tr></table></figure>
<p>在这段代码中,配置安全验证凭据通过username admin和password password.然后调用btoa()方法去获取Base64编码的用户凭证.</p>
<p>Authorization 被基本验证数据赋值,返回更新后的config对象. 开启基本验证这就足够了.接下来解释用angular js注册这个拦截器</p>
<h3 id="更新app-js"><a href="#更新app-js" class="headerlink" title="更新app.js"></a><strong>更新app.js</strong></h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">var app = angular.module(&#x27;userregistrationsystem&#x27;, [&#x27;ngRoute&#x27;, &#x27;ngResource&#x27;]);</span><br><span class="line">app.config(function ($routeProvider) &#123;</span><br><span class="line">    $routeProvider.when(&#x27;/list-all-users&#x27;, &#123;</span><br><span class="line">        templateUrl: &#x27;/template/listuser.html&#x27;,</span><br><span class="line">        controller: &#x27;listUserController&#x27;</span><br><span class="line">    &#125;).when(&#x27;/register-new-user&#x27;, &#123;</span><br><span class="line">        templateUrl: &#x27;/template/userregistration.html&#x27;,</span><br><span class="line">        controller: &#x27;registerUserController&#x27;</span><br><span class="line">    &#125;).when(&#x27;/update-user/:id&#x27;, &#123;</span><br><span class="line">        templateUrl: &#x27;/template/userupdation.html&#x27;, controller: &#x27;usersDetailsController&#x27;</span><br><span class="line">    &#125;).otherwise(&#123;redirectTo: &#x27;/home&#x27;, templateUrl: &#x27;/template/home.html&#x27;,&#125;);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">**app.config([&#x27;$httpProvider&#x27;,function ($httpProvider) &#123;</span><br><span class="line"></span><br><span class="line">    $httpProvider.interceptors.push(&#x27;AuthInterceptor&#x27;);</span><br><span class="line"></span><br><span class="line">&#125;])**</span><br></pre></td></tr></table></figure>
<p>在这个代码里,就是注册AuthInterceptor拦截器,使用$httpProvider,就是把拦截器放入interceptors数组里就好了</p>
<h3 id="更新index-html"><a href="#更新index-html" class="headerlink" title="更新index.html"></a><strong>更新index.html</strong></h3><p>就是引用这个JS文件,不过记得放在app.js的后面.</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">&lt;div ng-view&gt;&lt;/div&gt; </span><br><span class="line">&lt;script src=&quot;/webjars/angularjs/1.4.9/angular.js&quot;&gt;&lt;/script&gt; </span><br><span class="line">&lt;script src=&quot;/webjars/angularjs/1.4.9/angular-resource.js&quot;&gt;&lt;/script&gt; </span><br><span class="line">&lt;script src=&quot;/webjars/angularjs/1.4.9/angular-route.js&quot;&gt;&lt;/script&gt; </span><br><span class="line">&lt;script src=&quot;/js/app.js&quot;&gt;&lt;/script&gt; </span><br><span class="line">&lt;script src=&quot;/js/controller.js&quot;&gt;&lt;/script&gt; </span><br><span class="line">**&lt;script src=&quot;/js/authInterceptor.js&quot;&gt;&lt;/script&gt;** </span><br><span class="line">&lt;link rel=&quot;stylesheet&quot;href=&quot;/webjars/bootstrap/3.3.6/css/bootstrap.css&quot;&gt;</span><br></pre></td></tr></table></figure>
<p>这些做完后,访问网页,就不会要你登陆账号密码了.<br>至此你就成功在每一次请求的时候通过拦截器发送了授权头信息并且消费了受保护的REST API端点<br>你完成单个用户在angular JS拦截器中执行基本验证的配置.当你的用户超过一个且拥有不同角色时候会出现问题.<br>为了演示这个问题,需要一个能输入用户名和密码在访问资源之前去获取验证和授权的登陆页面,并且需要一个注销按钮</p>
<h1 id="登陆页面"><a href="#登陆页面" class="headerlink" title="登陆页面"></a>登陆页面</h1><p>这部分,将通过登陆表单使用angular JS去验证用户然后获取受保护资源再去将JSON数据渲染到UI里.</p>
<h2 id="更新-index-html-增加welcome-page-的导航"><a href="#更新-index-html-增加welcome-page-的导航" class="headerlink" title="更新 index.html: 增加welcome page 的导航"></a>更新 index.html: 增加welcome page 的导航</h2><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">&lt;nav class=&quot;navbar navbar-default&quot;&gt;</span><br><span class="line">    &lt;div class=&quot;container-fluid&quot;&gt;</span><br><span class="line">         &lt;div class=&quot;container-fluid&quot; ng-show=&quot;!authenticated&quot;&gt;</span><br><span class="line">            &lt;a href=&quot;#/login&quot; class=&quot;btn btn-info navbar-btn&quot; role=&quot;button&quot;&gt;</span><br><span class="line">                LOGIN</span><br><span class="line">            &lt;/a&gt;</span><br><span class="line">            &lt;p&gt;Login to go to Home Page&lt;/p&gt;</span><br><span class="line">        &lt;/div&gt;</span><br><span class="line">       &lt;div ng-show=&quot;authenticated&quot;&gt;</span><br><span class="line">            &lt;a href=&quot;#/&quot; class=&quot;btn btn-info navbar-btn&quot; role=&quot;button&quot;&gt; Home &lt;/a&gt;</span><br><span class="line">            &lt;a href=&quot;#/register-new-user&quot; class=&quot;btn btn-info navbar-btn&quot; role=&quot;button&quot;&gt; Register New User&lt;/a&gt;</span><br><span class="line">            &lt;a href=&quot;#/list-all-users&quot; class=&quot;btn btn-info&quot; role=&quot;button&quot;&gt; List All Users &lt;/a&gt;</span><br><span class="line">            &lt;a href=&quot;#logout&quot; class=&quot;btn btn-danger navbar-btn pull-right&quot; role=&quot;button&quot;&gt; Logout &lt;/a&gt;</span><br><span class="line">        &lt;/div&gt;</span><br><span class="line"></span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">&lt;/nav&gt;</span><br></pre></td></tr></table></figure>
<font face="微软雅黑" color="#0099ff" size="5">
    在原来的基础上增加了一个新DIV包含一个登陆链接,然后增加了一个登出链接.使用ng-show基于authenticated值来控制展示的DIV
</font>

<h2 id="曾加应用的导航"><a href="#曾加应用的导航" class="headerlink" title="曾加应用的导航"></a>曾加应用的导航</h2><p>你需要在app.js中为登陆和登出增加导航</p>
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">var app = angular.module(&#x27;userregistrationsystem&#x27;, [&#x27;ngRoute&#x27;, &#x27;ngResource&#x27;]);</span><br><span class="line">app.config(function ($routeProvider) &#123;</span><br><span class="line">    $routeProvider</span><br><span class="line">      .when(&#x27;/&#x27;,&#123;</span><br><span class="line">        templateUrl: &#x27;/template/home.html&#x27;,</span><br><span class="line">        controller: &#x27;homeController&#x27;</span><br><span class="line">      &#125;)</span><br><span class="line">      .when(&#x27;/list-all-users&#x27;, &#123;</span><br><span class="line">        templateUrl: &#x27;/template/listuser.html&#x27;,</span><br><span class="line">        controller: &#x27;listUserController&#x27;</span><br><span class="line">    &#125;).when(&#x27;/register-new-user&#x27;, &#123;</span><br><span class="line">        templateUrl: &#x27;/template/userregistration.html&#x27;,</span><br><span class="line">        controller: &#x27;registerUserController&#x27;</span><br><span class="line">    &#125;).when(&#x27;/update-user/:id&#x27;, &#123;</span><br><span class="line">        templateUrl: &#x27;/template/userupdation.html&#x27;, controller: &#x27;usersDetailsController&#x27;</span><br><span class="line">    &#125;).when(&#x27;/login&#x27;,&#123;</span><br><span class="line">        templateUrl: &#x27;/login/login.html&#x27;,</span><br><span class="line">        controller: &#x27;loginController&#x27;</span><br><span class="line">    &#125;).when(&#x27;/logout&#x27;,&#123;</span><br><span class="line">        templateUrl: &#x27;/login/login.html&#x27;,</span><br><span class="line">        controller: &#x27;logoutController&#x27;</span><br><span class="line">    &#125;).otherwise(&#123;</span><br><span class="line">        redirectTo: &#x27;/login&#x27;</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">app.config([&#x27;$httpProvider&#x27;,function ($httpProvider) &#123;</span><br><span class="line"></span><br><span class="line">    // $httpProvider.interceptors.push(&#x27;AuthInterceptor&#x27;);</span><br><span class="line">    $httpProvider.defaults.headers.common[&quot;X-Requested-With&quot;] = &#x27;XMLHttpRequest&#x27;;</span><br><span class="line">&#125;])</span><br></pre></td></tr></table></figure>
<p>增加了homeController 控制/.的链接,同样的建立了新链接如/login,/logout及他们的templateUrl和controller</p>
<p>定制X-Requested-With行是浏览器客户端发送的常规标头。Spring Security通过不在401响应中发送WWW-Authenticate标头来对此做出响应，因此浏览器将不会打开身份验证弹出对话框，这在您的UserRegistrationSystem应用程序中是理想的，因为您想控制身份验证。</p>
<h2 id="创建login-html-登陆表单"><a href="#创建login-html-登陆表单" class="headerlink" title="创建login.html:登陆表单"></a>创建login.html:登陆表单</h2><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">&lt;div class=&quot;container-fluid&quot;&gt;</span><br><span class="line">    &lt;div class=&quot;container&quot;&gt;</span><br><span class="line">        &lt;div class=&quot;panel panel-default &quot;&gt;</span><br><span class="line">            &lt;div class=&quot;alert alert-success&quot;&gt;</span><br><span class="line">                &lt;span class=&quot;lead&quot;&gt;Login Page&lt;/span&gt;</span><br><span class="line">                &lt;p&gt;Enter Username and Password&lt;/p&gt; &lt;br/&gt;</span><br><span class="line">                &lt;div class=&quot;alert alert-danger&quot; ng-show=&quot;loginerror&quot;&gt; There was a problem logging in. Please try</span><br><span class="line">                    again.</span><br><span class="line">                &lt;/div&gt;</span><br><span class="line">            &lt;/div&gt;</span><br><span class="line">            &lt;div class=&quot;panel-body &quot;&gt;</span><br><span class="line">                &lt;div class=&quot;container&quot;&gt;</span><br><span class="line">                    &lt;form ng-submit=&quot;loginUser()&quot; name=&quot;myForm&quot; class=&quot;form-horizontal&quot;&gt;</span><br><span class="line">                        &lt;div class=&quot;row&quot;&gt;</span><br><span class="line">                            &lt;div class=&quot;form-group col-md-12&quot;&gt;&lt;label class=&quot;col-md-2 control-lable&quot; for=&quot;uname&quot;&gt;</span><br><span class="line">                                Username &lt;/label&gt;</span><br><span class="line">                                &lt;div class=&quot;col-md-7&quot;&gt;&lt;input type=&quot;text&quot; ng-model=&quot;credentials.username&quot; id=&quot;uname&quot;</span><br><span class="line">                                                             class=&quot;form-control input-sm&quot;</span><br><span class="line">                                                             placeholder=&quot;Enter Username&quot;/&gt;&lt;/div&gt;</span><br><span class="line">                            &lt;/div&gt;</span><br><span class="line">                        &lt;/div&gt;</span><br><span class="line">                        &lt;div class=&quot;row&quot;&gt;</span><br><span class="line">                            &lt;div class=&quot;form-group col-md-12&quot;&gt;&lt;label class=&quot;col-md-2 control-lable&quot; for=&quot;password&quot;&gt;</span><br><span class="line">                                Password &lt;/label&gt;</span><br><span class="line">                                &lt;div class=&quot;col-md-7&quot;&gt;&lt;input type=&quot;password&quot; ng-model=&quot;credentials.password&quot;</span><br><span class="line">                                                             id=&quot;password&quot; class=&quot;form-control input-sm&quot;</span><br><span class="line">                                                             placeholder=&quot;Enter Password&quot;/&gt;&lt;/div&gt;</span><br><span class="line">                            &lt;/div&gt;</span><br><span class="line">                        &lt;/div&gt;</span><br><span class="line">                        &lt;div class=&quot;row&quot;&gt;</span><br><span class="line">                            &lt;div class=&quot;form-actions floatRight&quot;&gt;&lt;input type=&quot;submit&quot; value=&quot;Login&quot;</span><br><span class="line">                                                                        class=&quot;btn btn-primary btn-sm&quot;&gt;</span><br><span class="line">                                &lt;button type=&quot;button&quot; ng-click=&quot;resetForm()&quot; class=&quot;btn btn-warning btn-sm&quot;&gt;Reset Form</span><br><span class="line">                                &lt;/button&gt;</span><br><span class="line">                            &lt;/div&gt;</span><br><span class="line">                        &lt;/div&gt;</span><br><span class="line">                    &lt;/form&gt;</span><br><span class="line">                &lt;/div&gt;</span><br><span class="line">            &lt;/div&gt;</span><br><span class="line">        &lt;/div&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">&lt;/div&gt;</span><br></pre></td></tr></table></figure>

<p>登录表单控件使用ng-model在HTML（login.html）和Angular控制器（controller.js）之间传递数据，在这种情况下，您正在使用凭据对象保存用户名和密码。<br>您还添加了代码，以在Angular模型包含loginerror值时显示错误消息</p>
<h2 id="更新controller-js的代码"><a href="#更新controller-js的代码" class="headerlink" title="更新controller.js的代码"></a>更新controller.js的代码</h2><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">app.controller(&#x27;homeController&#x27;, function ($rootScope, $scope, $http, $location, $route) &#123;</span><br><span class="line">    if ($rootScope.authenticated) &#123;</span><br><span class="line">        $location.path(&quot;/&quot;);</span><br><span class="line">        $scope.loginerror = false;</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        $location.path(&quot;/login&quot;);</span><br><span class="line">        $scope.loginerror = true;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line">app.controller(&#x27;loginController&#x27;, function ($rootScope, $scope, $http, $location, $route) &#123;</span><br><span class="line">    $scope.credentials = &#123;&#125;;</span><br><span class="line">    $scope.resetForm = function () &#123;</span><br><span class="line">        $scope.credentials = null;</span><br><span class="line">    &#125;</span><br><span class="line">    var authenticate = function (credentials, callback) &#123;</span><br><span class="line">        var headers = $scope.credentials ? &#123;authorization: &quot;Basic &quot; + btoa($scope.credentials.username + &quot;:&quot; + $scope.credentials.password)&#125; : &#123;&#125;;</span><br><span class="line">        $http.get(&#x27;http://localhost:8080/user&#x27;, &#123;headers: headers&#125;).then(function (response) &#123;</span><br><span class="line">            if (response.data.name) &#123;</span><br><span class="line">                $rootScope.authenticated = true;</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                $rootScope.authenticated = false;</span><br><span class="line">            &#125;</span><br><span class="line">            callback &amp;&amp; callback();</span><br><span class="line">        &#125;, function () &#123;</span><br><span class="line">            $rootScope.authenticated = false;</span><br><span class="line">            callback &amp;&amp; callback();</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    authenticate();</span><br><span class="line"></span><br><span class="line">    $scope.loginUser = function () &#123;</span><br><span class="line">        authenticate($scope.credentials, function () &#123;</span><br><span class="line">            if ($rootScope.authenticated) &#123;</span><br><span class="line">                $location.path(&quot;/&quot;);</span><br><span class="line">                $scope.loginerror = false;</span><br><span class="line">            &#125; else &#123;</span><br><span class="line">                $location.path(&quot;/login&quot;);</span><br><span class="line">                $scope.loginerror = true;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">app.controller(&#x27;logoutController&#x27;, function ($rootScope, $scope, $http, $location, $route) &#123;</span><br><span class="line">    $http.post(&#x27;logout&#x27;, &#123;&#125;).finally(function () &#123;</span><br><span class="line">        $rootScope.authenticated = false;</span><br><span class="line">        $location.path(&quot;/&quot;);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>您创建了名为homeController，loginController和logoutController的新控制器。<br>homeController控制器检查$ rootScope内部经过身份验证的值是否为true，然后将带有$的$location.path和$ scopeto中的loginerror设置为false，或者将带有$login的$location.path和带有$scope中的loginerror设置为true</p>
<p>登录页面加载后，将执行loginController控制器。<br>该控制器首先初始化凭据对象，然后定义功能：resetForm（）方法，用于重置用户名和密码输入框为空值，authenticate（）函数（本地帮助程序函数）（从后端加载用户资源）以及表单中所需的函数loginUser（）。</p>
<p>加载控制器时，将查看本地帮助程序函数authenticate（），以查看用户是否已真正通过身份验证，并且您需要此函数只是进行远程调用，因为实际的身份验证是由服务器完成的。<br>此函数还设置了一个应用程序范围的标志，称为authenticated，您在index.html页面中使用了该标志来显示&#x2F;隐藏元素并控制呈现页面的哪些部分。<br>您可以使用$rootScope来实现此应用程序范围的标记，因为它很方便且易于遵循，并且需要在不同的控制器之间共享经过身份验证的标记</p>
<p>此authenticate（）方法对名为/user的相对资源进行GET调用。<br>从loginUser（）函数进行调用时，authenticate（）函数在请求标头中添加了Base64编码的凭据，因此在服务器上，它进行身份验证并接受cookie。<br>当登录用户获得用于控制登录页面中错误消息显示的身份验证结果时,loginUser()函数还将相应地设置本地$scope.loginerror标志</p>
<p>如果用户通过了身份验证，那么您将在每个网页上显示一个注销按钮。<br>单击注销按钮将使logoutController被执行。<br>logoutController控制器将HTTP POST发送到&#x2F;logout，您不需要在服务器上实现它，因为Spring Security已经为您添加了它。<br>为了对Spring Security提供的注销过程的默认行为进行更多控制，您可以使用Memory.java中HttpSecurity回调<br>的inSpringSecurityConfiguration来控制.例如在注销后执行一些业务逻辑</p>
<h2 id="修改后端代码"><a href="#修改后端代码" class="headerlink" title="修改后端代码"></a>修改后端代码</h2><p>您还需要更新后端代码，以支持UserRegistrationSystem应用程序中的登录和注销身份验证过程。</p>
<h3 id="创建一个新的RESTful端点以获取当前经过身份验证的用户"><a href="#创建一个新的RESTful端点以获取当前经过身份验证的用户" class="headerlink" title="创建一个新的RESTful端点以获取当前经过身份验证的用户"></a>创建一个新的RESTful端点以获取当前经过身份验证的用户</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">package com.zhang.myproject.rest;</span><br><span class="line"></span><br><span class="line">import org.springframework.web.bind.annotation.RequestMapping;</span><br><span class="line">import org.springframework.web.bind.annotation.RestController;</span><br><span class="line"></span><br><span class="line">import java.security.Principal;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * create by zhangbo on 2019/11/5 0005</span><br><span class="line"> */</span><br><span class="line">@RestController</span><br><span class="line">public class ServiceAuthenticate &#123;</span><br><span class="line"></span><br><span class="line">    @RequestMapping(&quot;/user&quot;)</span><br><span class="line">    public Principal user(Principal user) &#123;</span><br><span class="line"></span><br><span class="line">        return user;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>如果/user资源可访问，则它将返回经过身份验证的用户</p>
<h3 id="更新Spring-Security配置以处理登录请求"><a href="#更新Spring-Security配置以处理登录请求" class="headerlink" title="更新Spring Security配置以处理登录请求"></a>更新Spring Security配置以处理登录请求</h3><figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">   @Override</span><br><span class="line">    protected void configure(HttpSecurity http) throws Exception &#123;</span><br><span class="line"></span><br><span class="line">        http.sessionManagement()</span><br><span class="line">                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)</span><br><span class="line">                .and()</span><br><span class="line">                .httpBasic()</span><br><span class="line">                .realmName(&quot;User Registration System&quot;)</span><br><span class="line">                .and()</span><br><span class="line">                .authorizeRequests()</span><br><span class="line">                .antMatchers(&quot;/css/**&quot;, &quot;/js/**&quot;, &quot;/images/**&quot;, &quot;/webjars/**&quot;,&quot;/login/login.html&quot;,&quot;/template/home.html&quot;,&quot;/&quot;).permitAll()</span><br><span class="line">                .anyRequest().authenticated()</span><br><span class="line">                .and()</span><br><span class="line">                .csrf()</span><br><span class="line">                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>您更新了现有的configure方法以处理登录请求。<br>您允许匿名访问静态资源，例如/login/login.html、/template/home.html和/，因为匿名用户需要这些HTML资源。</p>
<p>Spring Security提供了一个特殊的CsrfTokenRepository来发送cookie。当您使用干净的浏览器Ctrl+F5或Chrome中的隐身模式<br>启动时，对服务器的第一个请求没有cookie，但是服务器发回JSESSIONID常规HttpSession和X-XSRF-TOKEN的Set-Cookie。是上面代码中设置的CRSF&nbsp;cookie.随后的请求将具有这些cookie,这很重要：没有它们,Spring Security应用程序将无法运行<br>,并且它们将提供一些真正的基本安全功能(身份验证和CSRF保护)。</p>
<p>当您注销时，cookie的值会更改。Spring Security希望在称为X-CSRF的标头中发送给它的令牌。从加载主页的初始请求中，从加载<br>主页的初始请求中，服务器端的HttpRequest属性中提供了CSRF令牌的值。Angular基于cookie内置了对CSRF（称为XSRF）的支持。Angular希望cookie名称为XSRF-TOKEN，Spring Security最好的部分是默认情况下将其作为请求属性提供</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>使用AngularJS成功使用了安全的RESTful服务。您首先在Spring Security中启用了基本身份验证。然后，您随每个请求发送了<br>一个授权标头。最后，您创建了一个登录页面以执行登录&#x2F;注销身份验证过程。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog">brad 随风起舞</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhangbo4881820.gitee.io/myblog/posts/12008/">https://zhangbo4881820.gitee.io/myblog/posts/12008/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhangbo4881820.gitee.io/myblog" target="_blank">静待花开</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/myblog/tags/%E5%AE%9E%E6%88%98/">实战</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/myblog/posts/21667/" title="全栈开发(RESTful和测试)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">全栈开发(RESTful和测试)</div></div></a></div><div class="next-post pull-right"><a href="/myblog/posts/62645/" title="Springboot热加载"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Springboot热加载</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/myblog/posts/45226/" title="全栈开发(AngularJS原理)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-01</div><div class="title">全栈开发(AngularJS原理)</div></div></a></div><div><a href="/myblog/posts/21667/" title="全栈开发(RESTful和测试)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-06</div><div class="title">全栈开发(RESTful和测试)</div></div></a></div><div><a href="/myblog/posts/20230/" title="全栈开发(Spring Security)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-04</div><div class="title">全栈开发(Spring Security)</div></div></a></div><div><a href="/myblog/posts/45057/" title="全栈开发(Spring Boot Actuator)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-07</div><div class="title">全栈开发(Spring Boot Actuator)</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/myblog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">brad 随风起舞</div><div class="author-info__description">有些事情需要一辈子的沉淀</div></div><div class="card-info-data site-data is-center"><a href="/myblog/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/myblog/tags/"><div class="headline">标签</div><div class="length-num">20</div></a><a href="/myblog/categories/"><div class="headline">分类</div><div class="length-num">25</div></a></div><a id="card-info-btn" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/xxxxx" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:xxxxxx@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9C%A8Angular-Js%E4%B8%AD%E5%8F%91%E9%80%81%E7%9A%84%E6%AF%8F%E4%B8%AA%E8%AE%BF%E9%97%AE%E9%83%BD%E5%B8%A6%E7%9D%80%E6%8E%88%E6%9D%83%E5%A4%B4"><span class="toc-number">1.</span> <span class="toc-text">在Angular Js中发送的每个访问都带着授权头</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8Angular-Js-%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%8B%A6%E6%88%AA%E5%99%A8"><span class="toc-number">1.1.</span> <span class="toc-text">在Angular Js 中添加拦截器</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#authInterceptor-js"><span class="toc-number">1.1.1.</span> <span class="toc-text">authInterceptor.js</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0app-js"><span class="toc-number">1.1.2.</span> <span class="toc-text">更新app.js</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0index-html"><span class="toc-number">1.1.3.</span> <span class="toc-text">更新index.html</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%99%BB%E9%99%86%E9%A1%B5%E9%9D%A2"><span class="toc-number">2.</span> <span class="toc-text">登陆页面</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0-index-html-%E5%A2%9E%E5%8A%A0welcome-page-%E7%9A%84%E5%AF%BC%E8%88%AA"><span class="toc-number">2.1.</span> <span class="toc-text">更新 index.html: 增加welcome page 的导航</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%BE%E5%8A%A0%E5%BA%94%E7%94%A8%E7%9A%84%E5%AF%BC%E8%88%AA"><span class="toc-number">2.2.</span> <span class="toc-text">曾加应用的导航</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BAlogin-html-%E7%99%BB%E9%99%86%E8%A1%A8%E5%8D%95"><span class="toc-number">2.3.</span> <span class="toc-text">创建login.html:登陆表单</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0controller-js%E7%9A%84%E4%BB%A3%E7%A0%81"><span class="toc-number">2.4.</span> <span class="toc-text">更新controller.js的代码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E5%90%8E%E7%AB%AF%E4%BB%A3%E7%A0%81"><span class="toc-number">2.5.</span> <span class="toc-text">修改后端代码</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%96%B0%E7%9A%84RESTful%E7%AB%AF%E7%82%B9%E4%BB%A5%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E7%BB%8F%E8%BF%87%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%E7%9A%84%E7%94%A8%E6%88%B7"><span class="toc-number">2.5.1.</span> <span class="toc-text">创建一个新的RESTful端点以获取当前经过身份验证的用户</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0Spring-Security%E9%85%8D%E7%BD%AE%E4%BB%A5%E5%A4%84%E7%90%86%E7%99%BB%E5%BD%95%E8%AF%B7%E6%B1%82"><span class="toc-number">2.5.2.</span> <span class="toc-text">更新Spring Security配置以处理登录请求</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">3.</span> <span class="toc-text">总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/15695/" title="jenkins（1）">jenkins（1）</a><time datetime="2023-09-14T02:17:44.000Z" title="发表于 2023-09-14 10:17:44">2023-09-14</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/22012/" title="wsl的Ubuntu子系统（1）">wsl的Ubuntu子系统（1）</a><time datetime="2023-09-13T08:42:19.000Z" title="发表于 2023-09-13 16:42:19">2023-09-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/30302/" title="effective-java-(接口优于抽象类)">effective-java-(接口优于抽象类)</a><time datetime="2023-09-12T08:12:48.000Z" title="发表于 2023-09-12 16:12:48">2023-09-12</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/9473/" title="effective-java(创建和销毁对象--组合的形式优于继承)">effective-java(创建和销毁对象--组合的形式优于继承)</a><time datetime="2023-09-11T08:23:19.000Z" title="发表于 2023-09-11 16:23:19">2023-09-11</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/myblog/posts/16107/" title="Hello World">Hello World</a><time datetime="2023-09-07T09:44:01.910Z" title="发表于 2023-09-07 17:44:01">2023-09-07</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By brad 随风起舞</div><div class="framework-info"><span>框架 </span><a href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/myblog/js/utils.js"></script><script src="/myblog/js/main.js"></script><script src="/myblog/js/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/myblog/js/search/local-search.js"></script></div></div></body></html>